<template>
  <!-- 悬浮广告 -->
  <div v-if="showAd" id="adContainer" class="ad-container" style="width: 800px">
    <!-- 跑马灯和广告内容 -->
    <span class="marquee-text" style="color: #b817d3">中秋活动专场:<br>1. 买一送一<br>2. 全场8折<br>3. 买就送精美礼品<br></span>
    <span class="marquee-text" style="color: #337ab7">本店国庆大降价:<br>1. 买一送一<br>2. 全场8折<br>3. 买就送精美礼品<br></span>
    <button @click="hideAd" class="close-button">X</button>
    <a @click="vx"><img src="../imgs/u=2653500309,2465436893&fm=253&fmt=auto&app=138&f=JPEG.webp" height="339" width="650"/></a>
    <!-- 显示倒计时 -->
    <span class="countdown">广告将在 {{ countdown }} 秒后关闭</span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showAd: true,
      countdown: 9, // 假设广告倒计时为10秒
    };
  },
  mounted() {
    this.startCountdown();
  },
  methods: {
    vx() {
      this.$router.push('/aavxin');
    },
    startCountdown() {
      let seconds = this.countdown;
      const intervalId = setInterval(() => {
        seconds--; // 每秒减少
        this.countdown = seconds;
        if (seconds <= 0) {
          this.showAd = false; // 倒计时结束，隐藏广告
          clearInterval(intervalId); // 清除计时器
        }
      }, 1000);
    },
    hideAd() {
      this.showAd = false;
    },
  },
};
</script>

<style scoped>
/* 悬浮广告样式 */
.ad-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px;
  background: linear-gradient(135deg, #31b36a 0%, #fda085 100%);
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  text-align: center;
  width: 300px;
  z-index: 1000;
}

.marquee-text {
  display: inline-block;
  position: relative;
  animation: marquee 10s linear infinite;
  color: #fff;
  font-size: 1.2em;
  font-weight: bold;
  padding: 0 20px;
}

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

.close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  cursor: pointer;
  background-color: #ff6666;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease, background-color 0.3s ease;
}

.close-button:hover {
  transform: scale(1.2);
  background-color: #ff3333;
}

.countdown {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  color: #e40909;
  font-size: 1em;
}
</style>